package com.enzoism.springboot.dive;

import com.enzoism.springboot.dive.model.Region;
import com.enzoism.springboot.dive.result.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/region")
public class RegionController {
    @Autowired
    private RegionService regionService;
    @Autowired
    private RegionSimpleService regionSimpleService;

    @GetMapping("/list")
    public RequestResult getList() {
        List<Region> regionList = regionService.selectRegionList(null); // 根据步骤三查到的集合(region表的全部数据)

        List<Region> tree = regionService.buildAreaTree(regionList); // 组装一个菜单树
        return RequestResult.success(tree); // 响应返回给前端页面的数据
    }

    @GetMapping("/simpleList")
    public RequestResult getSimpleLost(Region region) {
        List<Region> regionList = regionSimpleService.selectRegionList(region); // 根据步骤三查到的集合(region表的全部数据)

        List<Region> tree = regionSimpleService.buildAreaTree(regionList); // 组装一个菜单树
        return RequestResult.success(tree); // 响应返回给前端页面的数据
    }
}
